package cn.com.cfae.iras.doc.analyze.mq.consumer;

import cn.com.cfae.iras.doc.analyze.beans.integrity.IntegrityRegulation;
import cn.com.cfae.iras.doc.analyze.beans.integrity.IntegrityRegulationDetail;
import cn.com.cfae.iras.doc.analyze.beans.integrity.Rules;
import cn.com.cfae.iras.doc.analyze.beans.web.Commonsense;
import cn.com.cfae.iras.doc.analyze.beans.web.Consistency;
import cn.com.cfae.iras.doc.analyze.beans.web.Detail;
import cn.com.cfae.iras.doc.analyze.beans.web.Integrity;
import cn.com.cfae.iras.doc.analyze.beans.web.Rationality;
import cn.com.cfae.iras.doc.analyze.components.beans.ComponentResult;
import cn.com.cfae.iras.doc.analyze.config.ApplicationContextHelper;
import cn.com.cfae.iras.doc.analyze.mq.producer.DocAnalyzeProducer;
import cn.com.cfae.iras.doc.analyze.parse.PdfParser;
import cn.com.cfae.iras.doc.analyze.parse.model.ChapterModel;
import cn.com.cfae.iras.doc.analyze.parse.model.DocumentModel;
import cn.com.cfae.iras.doc.analyze.parse.model.TableType;
import cn.com.cfae.iras.doc.analyze.service.integrityregulation.IntegrityRegulationService;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import org.apache.commons.collections.MapUtils;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendCallback;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.UUID;

/**
 * Created by 佟媛媛 on 18/10/23.
 */
@Component
public class MessageHandler {

    private static Logger log = LoggerFactory.getLogger(MessageHandler.class);

    @Autowired
    private IntegrityRegulationService integrityRegulationService;
    @Value("${doc.analyze.save.path}")
    private String docAnalyzeSavePath;
    @Value("${analyze.output.save.path}")
    private String analyzeOutputSavePath;
    @Value("${rocketmq.topic.analyze_status}")
    private String topicAnalyzeStatus;


//    @Qualifier("analyzeStatusProducer")
//    private DefaultMQProducer analyzeStatusProducer;

    public JSONObject handleMessage(String topic, String tag, String messageBody) throws Exception {
        log.info("消费者监听" + topic + "[" + tag + "]收到消息：" + messageBody);
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
        String startTime = df.format(new Date());
        JSONObject returnMsg = new JSONObject();
        long t1 = System.currentTimeMillis();
        if (topic.equalsIgnoreCase("doc_analyze")) {//文本分析
//            {
//                    "documentId":"34tkjsadhfodge34236",
//                    "jobId":"34tkjsadhfodge34236",
//                    "fileType":["01","02"],
//                    "stage":"01",
//                    "type":"M",
//                    "subType":["M1","M4","M50"],
//                    "options":["1001","1002"]
//            }
//
//            字段释义：
//            fileType : 文件类型。 "01" 完整性, "02" 一致性, "03" 合理性,"04" 常识性,"05" iaad
//            stage: 发行阶段。"01"预评阶段，"02"发行阶段
//            type: 检查表类型 M/BM/DM/BDM
//            subType:子表
//            options:更多选项。"1001" 是否涉及投资人保护条款，"1002" 是否引用20xx年第xx期xx品种募集说明书 ;


//            返回：
//            {
//                    "documentId":"",
//                    "jobId":"",
//                    "code":"",
//                    "msg":"",
//                    "startTime":"",
//                    "endTime",""
//            }
            Gson gson = new GsonBuilder().create();
            Map rs = new HashMap();

            StringBuffer msg = new StringBuffer();
            int code = 0;
            //TODO 调用逻辑待添加
            if (StringUtils.isEmpty(messageBody)) {
                log.error("消息为空");
                code = -1004;
                msg.append("参数type错误");
            } else {
                JSONObject receiveMsg = JSONObject.parseObject(messageBody);
                String documentId = (String) receiveMsg.get("documentId");
                String jobId = (String) receiveMsg.get("jobId");
                String pdfPath = (String) receiveMsg.get("pdfPath");
                List<String> fileType = (List<String>) receiveMsg.get("fileType");
                String stage = (String) receiveMsg.get("stage");
                String type = (String) receiveMsg.get("type");
                List<String> subType = (List<String>) receiveMsg.get("subType");
                List<String> options = (List<String>) receiveMsg.get("options");
                List types = new ArrayList();
                if(subType!=null) types.addAll(subType);
                types.add(type);
                Map param = new HashMap();
                param.put("types", types);
                param.put("stage",stage);
                param.put("checkTypes",fileType);
                if(!CollectionUtils.isEmpty(options)){
                    for(String op : options){
                        if(op.equals("1001")){
                            param.put("protection","1001");
                        }else if(op.equals("1002")){
                            param.put("reference","1002");
                        }
                    }
                }

                TableType tableType = getTableType(type);
                if (tableType != null) {
                    File pdfFile = new File(pdfPath);
                    if (pdfFile.exists()) {
                        DocumentModel documentModel = analyze(pdfFile, tableType, documentId);//文本分析
                        if (documentModel != null) {
                            List<Map> list = integrityRegulationService.getComponentList(param);
                            if(!CollectionUtils.isEmpty(options)){
                                List<Map> _list = integrityRegulationService.getComponentList2(param);
                                list.addAll(_list);
                            }
                            for (Map m : list) {
                                String component = (String) m.get("component");
                                Class clazz = null;
                                String path = "";
                                try {
                                    String _package = "";
                                    if(component.contains("I")) _package = "integrity.";
                                    if(component.contains("C")) _package = "commonsense.";
                                    if(component.contains("U")) _package = "consistency.";
                                    if(component.contains("R")) _package = "rationality.";
                                    path = "cn.com.cfae.iras.doc.analyze.components."+ _package + component;
                                    clazz = Class.forName(path);
                                } catch (Exception e) {
//                                    code = -1003;
                                    msg.append(path + "组件不存在;");
                                    log.error(path + "组件不存在");
                                }
                                if (clazz != null && code == 0) {
                                    Map map = handler(component, clazz, documentModel, type,stage,m);//初始化组件并向组件注入数据
                                    Map webData = getWebData(component,rs, map, fileType, documentId);
                                    rs.putAll(webData);
                                }
                            }
                            String webPath = analyzeOutputSavePath + File.separator + documentId + File.separator + "analyze.output.json";
                            writeFile(new ObjectMapper().writeValueAsString(rs), webPath);//前端显示数据写入文件
                            log.info("前端展示数据：{}", new ObjectMapper().writeValueAsString(rs));
                        } else {
                            code = -1005;
                            msg.append("文件抽取失败");
                        }
                    } else {
                        code = -1002;
                        msg.append(pdfFile.getAbsolutePath() + "文件不存在");
                    }
                } else {
                    code = -1001;
                    msg.append("参数type错误");
                }
                String endTime = df.format(new Date());
                returnMsg.put("code", code);
                returnMsg.put("msg", msg);
                returnMsg.put("documentId", documentId);
                returnMsg.put("jobId", jobId);
                returnMsg.put("startTime", startTime);
                returnMsg.put("endTime", endTime);
                sendMsg(returnMsg, tag);//向analyze_status发送消息
                log.info("{}", returnMsg);
            }
        } else {
            log.error(topic + "错误");
        }
        long t2 = System.currentTimeMillis();
        log.info("{}处理消息耗时：{}ms",messageBody,(t2-t1));
        return returnMsg;
    }

    /**
     * @auth 佟媛媛
     * @date 18/10/27 下午5:50
     * @desc 完整性
     */
    private Map getIntegrity(Map rs, Map map) {
        Integrity integrity = (Integrity) rs.get("integrity");
        if (integrity == null) integrity = new Integrity();
        List<Detail> _disclosedList = integrity.getDisclosed() != null ? integrity.getDisclosed() : new ArrayList<>();
        List<Detail> _undisclosedList = integrity.getUndisclosed() != null ? integrity.getUndisclosed() : new ArrayList<>();
        List<Detail> _seemDisclosedList = integrity.getSeemDisclosed() != null ? integrity.getSeemDisclosed() : new ArrayList<>();
        if (MapUtils.isNotEmpty(map)) {
            List<Detail> disclosedList = (List<Detail>) map.get("disclosed");
            List<Detail> undisclosedList = (List<Detail>) map.get("undisclosed");
            List<Detail> seemDisclosedList = (List<Detail>) map.get("seem_disclosed");
            if (disclosedList != null) _disclosedList.addAll(disclosedList);
            if (undisclosedList != null) _undisclosedList.addAll(undisclosedList);
            if (seemDisclosedList != null) _seemDisclosedList.addAll(seemDisclosedList);

        }
        integrity.setDisclosed(_disclosedList);
        integrity.setUndisclosed(_undisclosedList);
        integrity.setSeemDisclosed(_seemDisclosedList);
        rs.put("integrity", integrity);
        return rs;
    }

    /**
     * @auth 佟媛媛
     * @date 18/10/27 下午5:51
     * @desc 一致性
     */
    private Map getConsistency(Map rs, Map map) {
        Consistency consistency = (Consistency) rs.get("consistency");
        if (consistency == null) consistency = new Consistency();
        List<Detail> _conflictList = consistency.getConflict() != null ? consistency.getConflict() : new ArrayList<>();
        List<Detail> _rightList = consistency.getRight() != null ? consistency.getRight() : new ArrayList<>();
        List<Detail> _seemRightList = consistency.getSeemRight() != null ? consistency.getSeemRight() : new ArrayList<>();
        List<Detail> _onlyList = consistency.getOnly() != null ? consistency.getOnly() : new ArrayList<>();
        if (MapUtils.isNotEmpty(map)) {
            List<Detail> conflictList = (List<Detail>) map.get("conflict");
            List<Detail> rightList = (List<Detail>) map.get("right");
            List<Detail> seemRightList = (List<Detail>) map.get("seem_right");
            List<Detail> onlyList = (List<Detail>) map.get("only");
            if (conflictList != null) _conflictList.addAll(conflictList);
            if (rightList != null) _rightList.addAll(rightList);
            if (seemRightList != null) _seemRightList.addAll(seemRightList);
            if (onlyList != null) _onlyList.addAll(onlyList);
        }
        consistency.setConflict(_conflictList);
        consistency.setRight(_rightList);
        consistency.setSeemRight(_seemRightList);
        consistency.setOnly(_onlyList);
        rs.put("consistency", consistency);
        return rs;
    }


    /**
     * @auth 佟媛媛
     * @date 18/10/27 下午5:52
     * @desc 合理性
     */
    private Map getRationality(Map rs, Map map) {
        Rationality rationality = (Rationality) rs.get("rationality");
        if (rationality == null) rationality = new Rationality();
        List<Detail> _reasonableList = rationality.getReasonable() != null ? rationality.getReasonable() : new ArrayList<>();
        List<Detail> _unreasonableList = rationality.getUnreasonable() != null ? rationality.getUnreasonable() : new ArrayList<>();
        List<Detail> _waitList = rationality.getWait() != null ? rationality.getWait() : new ArrayList<>();
        if (MapUtils.isNotEmpty(map)) {
            List<Detail> reasonableList = (List<Detail>) map.get("reasonable");
            List<Detail> unreasonableList = (List<Detail>) map.get("unreasonable");
            List<Detail> waitList = (List<Detail>) map.get("wait");
            if (reasonableList != null) _reasonableList.addAll(reasonableList);
            if (unreasonableList != null) _unreasonableList.addAll(unreasonableList);
            if (waitList != null) _waitList.addAll(waitList);
        }
        rationality.setReasonable(_reasonableList);
        rationality.setUnreasonable(_unreasonableList);
        rationality.setWait(_waitList);
        rs.put("rationality", rationality);
        return rs;
    }

    /**
     * @auth 佟媛媛
     * @date 18/10/27 下午5:52
     * @desc 常识性
     */
    private Map getCommonsense(Map rs, Map map) {
        Commonsense commonsense = (Commonsense) rs.get("commonsense");
        if (commonsense == null) commonsense = new Commonsense();
        List<Detail> _errorList = commonsense.getError() != null ? commonsense.getError() : new ArrayList<>();
        List<Detail> _seemErrorList = commonsense.getSeemRrror() != null ? commonsense.getSeemRrror() : new ArrayList<>();
        if (MapUtils.isNotEmpty(map)) {
            List<Detail> errorList = (List<Detail>) map.get("error");
            List<Detail> seemErrorList = (List<Detail>) map.get("seem_error");
            if (errorList != null) _errorList.addAll(errorList);
            if (seemErrorList != null) _seemErrorList.addAll(seemErrorList);
        }
        commonsense.setError(_errorList);
        commonsense.setSeemRrror(_seemErrorList);
        rs.put("commonsense", commonsense);
        return rs;
    }

    /**
     * @auth 佟媛媛
     * @date 18/10/30 上午10:10
     * @desc 将componentResultList转换为最终结构
     */
    public Map componentResultTrans(String component, List<ComponentResult> componentResultList){
        Map rs = new HashMap();
        Map<String,String> ruleNameMap = new HashMap();
        List<Detail> list01 = new ArrayList<>();
        List<Detail> list02 = new ArrayList<>();
        List<Detail> list03 = new ArrayList<>();
        List<Detail> list04 = new ArrayList<>();
        if(!CollectionUtils.isEmpty(componentResultList)){
            for(ComponentResult componentResult : componentResultList){
                ruleNameMap.put(componentResult.getRuleName(),componentResult.getRuleName());
            }
            for(String key : ruleNameMap.keySet()){
                List<Detail.Result> resultList01 = new ArrayList<>();
                List<Detail.Result> resultList02 = new ArrayList<>();
                List<Detail.Result> resultList03 = new ArrayList<>();
                List<Detail.Result> resultList04 = new ArrayList<>();
                for(ComponentResult componentResult : componentResultList){
                    Detail detail = new Detail();
                    String catalog_id = componentResult.getCatalogId();
                    String chapter_id = componentResult.getChapterId();
                    String rule_name = componentResult.getRuleName();
                    List<ComponentResult.TextPosition> textPositionList = componentResult.getTextPosition();
                    String exist = componentResult.getExist();
                    if(key.equals(rule_name)){
                        detail.setCatalogId(catalog_id);
                        detail.setRuleName(rule_name);
                        Detail.Result result = new Detail().new Result();
                        result.setChapterId(chapter_id);
                        result.setUid(UUID.randomUUID().toString());
                        result.setKeyword(componentResult.getKeyword());
                        result.setPromptMessage(componentResult.getPromptMessage());
                        result.setRegulationId(componentResult.getRegulationId());
                        result.setTextPosition(textPositionTrans(textPositionList));
                        result.setPageNum(componentResult.getPageNum());
                        result.setAnnotationFlag(componentResult.getAnnotationFlag());
                        if("01".equals(exist)){
                            resultList01.add(result);
                            detail.setResults(resultList01);
                            if(!ifInList(list01,catalog_id)) list01.add(detail);
                        }else if("02".equals(exist)){
                            resultList02.add(result);
                            detail.setResults(resultList02);
                            if(!ifInList(list02,catalog_id)) list02.add(detail);
                        }else if("03".equals(exist)){
                            resultList03.add(result);
                            detail.setResults(resultList03);
                            if(!ifInList(list03,catalog_id)) list03.add(detail);
                        }else if("04".equals(exist)){
                            resultList04.add(result);
                            detail.setResults(resultList04);
                            if(!ifInList(list04,catalog_id)) list04.add(detail);
                        }
                    }
                }

            }
        }
        if(component.contains("I")){
            rs.put("disclosed",list01);
            rs.put("undisclosed",list02);
            rs.put("seem_disclosed",list03);
        }else if(component.contains("C")){
            rs.put("error",list02);
            rs.put("seem_error",list03);
        }else if(component.contains("U")){
            rs.put("conflict",list02);
            rs.put("right",list01);
            rs.put("seem_right",list03);
            rs.put("only",list04);
        }else if(component.contains("R")){
            rs.put("reasonable",list01);
            rs.put("unreasonable",list02);
            rs.put("wait",list03);
        }
        return rs;
    }

    private boolean ifInList(List<Detail> list,String value){
        if(CollectionUtils.isEmpty(list)){
            return false;
        }
        for(Detail d : list){
            if(!StringUtils.isEmpty(d.getCatalogId()) && d.getCatalogId().equals(value)){
                return true;
            }
        }
        return false;
    }

    private List<Detail.TextPosition> textPositionTrans(List<ComponentResult.TextPosition> textPositionList){
        List<Detail.TextPosition> list = new ArrayList<>();
        if(CollectionUtils.isEmpty(textPositionList)){
            return list;
        }
        for(ComponentResult.TextPosition textPosition : textPositionList){
            Detail.TextPosition _textPosition = new Detail().new TextPosition();
            _textPosition.setX(textPosition.getX());
            _textPosition.setY(textPosition.getY());
            _textPosition.setContent(textPosition.getContent());
            list.add(_textPosition);
        }
        return list;
    }

    /**
     * @auth 佟媛媛
     * @date 18/10/27 下午5:53
     * @desc 拼装前端显示数据文件并写入文件
     */
    private Map getWebData(String component,Map rs, Map map, List<String> fileType, String documentId) {
        if(!"I1001".equals(component)){
            List<ComponentResult> componentResultList = (List<ComponentResult>)map.get("componentResultList");
            map = componentResultTrans(component,componentResultList);
        }
        if (fileType != null && fileType.size() > 0) {//"01" 完整性, "02" 一致性, "03" 合理性,"04" 常识性,"05" iaad
            for (String t : fileType) {
                if (t.equals("01")) {
                    rs.putAll(getIntegrity(rs, map));
                }
                if (t.equals("02")) {
                    rs.putAll(getConsistency(rs, map));
                }
                if (t.equals("03")) {
                    rs.putAll(getRationality(rs, map));
                }
                if (t.equals("04")) {
                    rs.putAll(getCommonsense(rs, map));
                }
            }
        }
        return rs;
    }

    /**
     * @auth 佟媛媛
     * @date 18/10/25 下午7:02
     * @desc 向MQ发送消息
     */
    private void sendMsg(JSONObject message, String tag) {
        try {

            DefaultMQProducer analyzeStatusProducer=(DefaultMQProducer)ApplicationContextHelper.getBean("analyzeStatusProducer");

            Message msg = new Message(topicAnalyzeStatus, tag, message.toJSONString().getBytes("UTF-8"));
            analyzeStatusProducer.send(msg, new SendCallback() {

                @Override
                public void onSuccess(SendResult sendResult) {
                    log.info("生产者向" + topicAnalyzeStatus + "[" + tag + "]" + "发送消息：" + message + ";发送状态：" + sendResult.getSendStatus());
                }

                @Override
                public void onException(Throwable e) {
                    log.error(e.getMessage(), e);
                }
            });
        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }


    /**
     * @auth 佟媛媛
     * @date 18/10/25 下午6:20
     * @desc 分析文本并写入文件
     */
    private DocumentModel analyze(File pdfFile, TableType tableType, String documentId) {
        DocumentModel documentModel = null;
        log.info("开始解析文本{},类型:{}", pdfFile.getAbsolutePath(), tableType);
        long t1 = System.currentTimeMillis();
        try{
            String outputPath = docAnalyzeSavePath + File.separator + documentId + File.separator + "doc.analyze.json";
            Gson gson = new GsonBuilder().create();
            PdfParser pdfParser = new PdfParser();
            documentModel = pdfParser.parsePdfOutline(pdfFile, tableType);
            String content = gson.toJson(documentModel);
            writeFile(content, outputPath);//结果写入文件
        }catch (Exception e){
            log.error(e.getMessage(),e);
            return null;
        }
        long t2 = System.currentTimeMillis();
        log.info("数据分析存储耗时：{}ms", t2 - t1);
        return documentModel;
    }

    /**
     * @auth 佟媛媛
     * @date 18/10/25 下午6:21
     * @desc 写文件
     */
    private void writeFile(String content, String filePath) {
        try {
            File file = new File(filePath);
            if (!file.getParentFile().exists()) file.getParentFile().mkdirs();
            if (file.exists()) file.delete();
            file.createNewFile();
            FileWriter fileWritter = new FileWriter(file.getAbsoluteFile());
            fileWritter.write(content);
            fileWritter.flush();
            fileWritter.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    /**
     * @auth 佟媛媛
     * @date 18/10/25 下午6:21
     * @desc 获取TableType
     */
    private TableType getTableType(String type) {
        TableType tableType = null;
        switch (type) {
            case "M":
                tableType = TableType.M;
                break;
            case "BM":
                tableType = TableType.BM;
                break;
            case "DM":
                tableType = TableType.DM;
                break;
            case "BDM":
                tableType = TableType.BDM;
                break;
        }
        return tableType;
    }

    /**
     * @auth 佟媛媛
     * @date 18/10/25 下午6:21
     * @desc 初始化组件并向组件注入数据
     */
    private Map handler(String component, Class clazz, DocumentModel documentModel,String type,String stage,Map m)throws Exception {
        Gson gson = new GsonBuilder().create();
        List<Map> mapList = new ArrayList<>();
        Map webMap = new HashMap();
        String regulationId = (String) m.get("regulationId");
        String catalogId = (String)m.get("catalogId");
        String ruleTitle = (String)m.get("ruleTitle");
        String chapterId = (String)m.get("chapterId");
        try {
            IntegrityRegulation integrityRegulation = new IntegrityRegulation();
            integrityRegulation.setRegulationId(regulationId);
            List<IntegrityRegulation> integrityRegulationList = integrityRegulationService.getIntegrityRegulationList(integrityRegulation);
            Object obj = ApplicationContextHelper.getBean(component);
            //注入抽取数据
            Method setExtractData = clazz.getMethod("setExtractData", DocumentModel.class);
            setExtractData.invoke(obj, documentModel);
            //注入目录ID
            Method setCatalogId = clazz.getMethod("setCatalogId", String.class);
            setCatalogId.invoke(obj, catalogId);
            //注入章节ID
            Method setChapterId = clazz.getMethod("setChapterId", String.class);
            setChapterId.invoke(obj, chapterId);
            //注入规则ID
            Method setRegulationId = clazz.getMethod("setRegulationId",String.class);
            setRegulationId.invoke(obj,regulationId);
            //注入规则名称
            Method setRuleTitle = clazz.getMethod("setRuleTitle",String.class);
            setRuleTitle.invoke(obj,ruleTitle);
            //注入阶段类型
            Method setStage = clazz.getMethod("setStage",String.class);
            setStage.invoke(obj,stage);

            if ("I1001".equals(component)) {
                if (!CollectionUtils.isEmpty(integrityRegulationList)) {
                    for(IntegrityRegulation regulation : integrityRegulationList){
                        List<IntegrityRegulationDetail> integrityRegulationDetailList = regulation.getIntegrityRegulationDetailList();
                        if(!CollectionUtils.isEmpty(integrityRegulationDetailList)){
                            for (IntegrityRegulationDetail detail : integrityRegulationDetailList) {
                                Method setKeyword = clazz.getMethod("setKeyword", String.class);//参数keyword
                                setKeyword.invoke(obj, detail.getRegulationDetail());
                                Method handler = clazz.getMethod("_handler" + type);
                                Map map = (Map) handler.invoke(obj);
                                if (MapUtils.isNotEmpty(map)) {
                                    map.putAll(gson.fromJson(gson.toJson(integrityRegulationList.get(0)),Map.class));
                                    map.putAll(gson.fromJson(gson.toJson(detail),Map.class));
                                    mapList.add(map);
                                }
                            }
                        }
                    }
                }
                Method getWebData = clazz.getMethod("getWebData", List.class);//参数List<Map> mapList,List<String> fileType
                webMap = (Map) getWebData.invoke(obj, mapList);
            } else {

                Method handler = clazz.getDeclaredMethod("handler" + type);
                List<ComponentResult> componentResultList = (List<ComponentResult>) handler.invoke(obj);
                webMap.put("componentResultList",componentResultList);
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }

        log.info("{}前端数据展示：{}", component, new ObjectMapper().writeValueAsString(webMap));
        return webMap;
    }





}
